<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>parentNode-原生js仿jquery中的sibling方法</title>
    <style type="text/css">
        ul li{
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<ul>
	<li id="firstId">
		<span>我是文本</span>
	</li>
	<li></li>
	<li></li>
</ul>
</body>
<script type="text/javascript">
window.onload=function(){
   var firstId=document.getElementById("firstId");
   const elm=mySiblings(firstId);
   for (let i = 0; i < elm.length; i++) {
      elm[i].style.background="red";
   }
}

function mySiblings(elm) {
  var siblingsNodes = [];
  var p = elm.parentNode.children;
  for(let i =0,pl= p.length;i<pl;i++) {
    if(p[i] !== elm) siblingsNodes.push(p[i]);
  }
  return siblingsNodes;
}
</script>
</html>